extends TileMap

var astar := AStarGrid2D.new()


func _ready() -> void:
	astar.region = get_used_rect()
	astar.cell_size = get_tileset().tile_size
	
	#设置为不能走斜线
	astar.default_compute_heuristic= AStarGrid2D.HEURISTIC_MANHATTAN
	astar.default_estimate_heuristic = AStarGrid2D.HEURISTIC_MANHATTAN
	astar.diagonal_mode = AStarGrid2D.DIAGONAL_MODE_NEVER
	astar.update()
	
	for x in range(astar.region.position.x,astar.region.end.x):
		for y in range(astar.region.position.y,astar.region.end.y):
			var coord = Vector2i(x,y)
			for layer in get_layers_count():
				var tile_data = get_cell_tile_data(layer,coord)
				if tile_data and tile_data.get_custom_data("unwalkable"):
					astar.set_point_solid(coord)
	
	
